home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / wrnsr094 / message.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  10.1 KB  |  315 lines

  1. VERSION 2.00
  2. Begin Form Message 
  3.    Caption         =   "Messages"
  4.    ClientHeight    =   8310
  5.    ClientLeft      =   165
  6.    ClientTop       =   345
  7.    ClientWidth     =   5085
  8.    Height          =   8715
  9.    Icon            =   MESSAGE.FRX:0000
  10.    Left            =   105
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    ScaleHeight     =   8310
  15.    ScaleWidth      =   5085
  16.    Top             =   0
  17.    Width           =   5205
  18.    Begin PictureBox List1 
  19.       BackColor       =   &H000000FF&
  20.       Height          =   1000
  21.       Left            =   0
  22.       ScaleHeight     =   975
  23.       ScaleWidth      =   975
  24.       TabIndex        =   2
  25.       Top             =   0
  26.       Width           =   1000
  27.    End
  28.    Begin ComboBox Combo1 
  29.       BackColor       =   &H00C0FFC0&
  30.       Height          =   300
  31.       Left            =   480
  32.       TabIndex        =   0
  33.       Text            =   "No Mail or News available"
  34.       Top             =   120
  35.       Width           =   4575
  36.    End
  37.    Begin PictureBox catchup_btn 
  38.       Height          =   495
  39.       Left            =   0
  40.       Picture         =   MESSAGE.FRX:0302
  41.       ScaleHeight     =   465
  42.       ScaleWidth      =   465
  43.       TabIndex        =   1
  44.       Top             =   0
  45.       Width           =   495
  46.    End
  47. Function calc_usercode (ByVal userid$) As Integer
  48.    total! = 0
  49.    For i% = 1 To Len(userid$)
  50.       ch% = Asc(Mid$(userid$, i%, 1))
  51.       total! = total! + Int(ch% / 16) * 17 + (ch% Mod 16) * 23
  52.    Next i%
  53.    total! = total! Mod 32767
  54.    calc_usercode = total! - 1309
  55. End Function
  56. Sub catchup_btn_Click ()
  57.    If message.combo1.listcount = 0 Then
  58.       Unload edit
  59.       End
  60.    End If
  61.    Call clear_msg_list
  62.    If reading_mail Then
  63.       Kill mail_file$ + ".f"
  64.       Kill mail_file$ + ".i"
  65.    Else
  66.       If message.combo1.listindex <> -1 Then
  67.          Call make_dir(message.combo1.list(message.combo1.listindex), dir_name$)
  68.          Kill dir_name$ + "*.*"
  69.       End If
  70.    End If
  71.    cur_item = message.combo1.listindex
  72.    message.combo1.RemoveItem message.combo1.listindex
  73.    If cur_item < message.combo1.listcount Then
  74.       message.combo1.listindex = cur_item
  75.    Else
  76.       message.combo1.listindex = message.combo1.listcount - 1
  77.    End If
  78. End Sub
  79. Sub clear_msg_list ()
  80.    list1.visible = True
  81.    list1.empty = True
  82.    edit.message_text.Text = ""
  83. End Sub
  84. Sub Combo1_Click ()
  85.    Call clear_msg_list
  86.    If combo1.list(combo1.listindex) = "MAIL" Then
  87.       reading_mail = True
  88.       Call read_mail
  89.    Else
  90.       reading_mail = False
  91.       Call make_dir(combo1.list(combo1.listindex), dir_name$)
  92.       file_name$ = Dir$(dir_name$ + "*.*")
  93.       While (Len(file_name$) <> 0)
  94.          Call extract_param(dir_name$ + file_name$, "Subject", subj_line$)
  95.          If Len(subj_line$) = 0 Then
  96.             subj_line$ = "<None>"
  97.          End If
  98.          Call extract_param(dir_name$ + file_name$, "From", author$)
  99.          If Len(author$) <> 0 Then
  100.             If (InStr(author$, "(") <> 0) And (InStr(author$, ")") <> 0) Then
  101.                author$ = Mid$(author$, InStr(author$, "(") + 1)
  102.                author$ = Left$(author$, InStr(author$, ")") - 1)
  103.             End If
  104.             subj_line$ = subj_line$ + "; " + Chr$(9) + author$
  105.          End If
  106.          list1.AddItem file_name$ + ": " + subj_line$
  107.          file_name$ = Dir$
  108.       Wend
  109.    End If
  110.    If list1.listcount <> 0 Then
  111.       list1.topindex = 0
  112.    End If
  113. End Sub
  114. Sub Form_Load ()
  115.    new_line = Chr$(13) + Chr$(10)
  116.    Randomize
  117.    reply_written = False
  118.    If Len(Dir$("WRN.INI")) = 0 Then
  119.       MsgBox "WRN.INI not found in Current directory", 16, "Fatal Error"
  120.       End
  121.    End If
  122.    usenet_file$ = read_ini("UseNetFile")
  123.    news_dir$ = read_ini("NewsDir")
  124.    If Right$(news_dir$, 1) <> "\" Then
  125.       news_dir$ = news_dir$ + "\"
  126.    End If
  127.    msg_quote$ = read_ini("QuotePrefix")
  128.    static_file$ = read_ini("StaticFile")
  129.    user_id$ = read_ini("UserID")
  130.    registered = Val(read_ini("UserCode")) = calc_usercode(user_id$)
  131.    If Not registered Then
  132.       Select Case Int(Rnd * 4)
  133.       Case 0
  134.          nagbox.BTN_OK.caption = "Continue"
  135.       Case 1
  136.          nagbox.BTN_OK.caption = "Resume"
  137.       Case 2
  138.          nagbox.BTN_OK.caption = "Click"
  139.       Case Else
  140.          nagbox.BTN_OK.caption = "OK"
  141.       End Select
  142.       nagbox.Show
  143.       While nagbox.visible
  144.          dummy% = DoEvents()
  145.       Wend
  146.    End If
  147.    time_zone$ = read_ini("TimeZone")
  148.    site_name$ = read_ini("SiteID")
  149.    full_name$ = read_ini("UserName")
  150.    organisation$ = read_ini("Organisation")
  151.    out_path$ = read_ini("MailOutDir")
  152.    If Right$(out_path$, 1) <> "\" Then
  153.       out_path$ = out_path$ + "\"
  154.    End If
  155.    seq_path$ = read_ini("SeqFile")
  156.    out_news_list = read_ini("NewsOutList")
  157.    sign_filename = read_ini("SigFile")
  158.    news_reply$ = read_ini("NewsReply")
  159.    If Right$(news_reply$, 1) <> "\" Then
  160.       news_reply$ = news_reply$ + "\"
  161.    End If
  162.    uudecoder$ = read_ini("UUDecode")
  163.    batch_exe$ = read_ini("Batch")
  164. Rem MsgBox "Finished with .INI, reading STATIC", 16, "Info"
  165.    Call extract_param(static_file$, "user", mail_file$)
  166.    Call change_chars("/", "\", mail_file$)
  167.    mail_file$ = mail_file$ + "\" + user_id$ + "\mailbox"
  168.    If Dir$(mail_file$ + ".f") <> "" Then
  169.       message.combo1.list(0) = "MAIL"
  170.       gcnt = 1
  171.    Else
  172.       gcnt = 0
  173.    End If
  174.    text_changed = 0
  175.    usenet_fileid = fopen(usenet_file$, "r")
  176.    file_contents$ = Input$(LOF(usenet_fileid), #usenet_fileid)
  177.    Close #usenet_fileid
  178.    If Len(Dir$(news_dir$ + "CONTROL\*.*")) <> 0 Then
  179.       Kill news_dir$ + "CONTROL\*.*"
  180.    End If
  181.    If Len(Dir$(news_dir$ + "MONITOR\*.*")) <> 0 Then
  182.       Kill news_dir$ + "MONITOR\*.*"
  183.    End If
  184.    prev_eol = 0
  185.    eol = InStr(file_contents$, Chr$(10))
  186.    While eol <> 0
  187.       join_line$ = Mid$(file_contents$, prev_eol + 1, eol - prev_eol - 2)
  188.       If Left$(join_line$, 1) <> "#" And UCase$(Left$(join_line$, 7)) <> "DEFAULT" Then
  189.          pos = InStr(UCase$(join_line$), "/DIR=")
  190.          If pos <> 0 Then
  191.             join_line$ = Mid$(join_line$, pos + 6)
  192.             join_line$ = Left$(join_line$, InStr(join_line$, Chr$(34)) - 1)
  193.          Else
  194.             pos = InStr(join_line$, " ")
  195.             tab_pos = InStr(join_line$, Chr$(9))
  196.             If (tab_pos <> 0 And tab_pos < pos) Or pos = 0 Then
  197.                pos = tab_pos
  198.             End If
  199.             If pos <> 0 Then
  200.                join_line$ = Left$(join_line$, pos - 1)
  201.             End If
  202.          End If
  203.          Call make_dir(join_line$, dir_name$)
  204.          If Len(Dir$(dir_name$ + "*.*")) <> 0 Then
  205.             message.combo1.list(gcnt) = join_line$
  206.             gcnt = gcnt + 1
  207.          End If
  208.       End If
  209.       prev_eol = eol
  210.       eol = InStr(eol + 1, file_contents$, Chr$(10))
  211.    Wend
  212.    If message.combo1.listcount = 0 Then
  213.       edit.Show 0
  214.    Else
  215.       message.Show 0
  216.       message.combo1.listindex = 0
  217.    End If
  218. End Sub
  219. Sub Form_Resize ()
  220.    list1.width = message.scalewidth
  221.    combo1.width = message.scalewidth - catchup_btn.width
  222.    list1.height = message.scaleheight - catchup_btn.height
  223. End Sub
  224. Sub Form_Unload (Cancel As Integer)
  225.    If reply_written Then
  226.       res = Shell(batch_exe, 1)
  227.    End If
  228.    End
  229. End Sub
  230. Sub List1_DblClick ()
  231.    If list1.listcount = 0 Then
  232.       catchup_btn.value = True
  233.    End If
  234.    If list1.listindex = -1 Then
  235.       list1.listindex = 0
  236.    End If
  237.    If combo1.list(combo1.listindex) = "MAIL" Then
  238.       reading_mail = True
  239.       msg_text$ = get_mail(list1.listindex)
  240.       subject$ = list1.list(list1.listindex)
  241.    Else
  242.       reading_mail = False
  243.       subject$ = list1.list(list1.listindex)
  244.       msg_filename$ = dir_name$ + Left$(subject$, InStr(subject$, ":") - 1)
  245.       subject$ = LTrim$(Mid$(subject$, InStr(subject$, ":") + 1))
  246.       If InStr(subject$, Chr$(9)) <> 0 Then
  247.          subject$ = Left$(subject$, InStr(subject$, Chr$(9)) - 2)
  248.       End If
  249.       msg_text$ = load_file(msg_filename$)
  250.    End If
  251.    Call split_header(msg_text$, header$)
  252.    Call word_wrap(msg_text$, 80)
  253.    While Left$(subject$, 3) = "Re:"
  254.       subject$ = LTrim$(Mid$(subject$, 4))
  255.    Wend
  256.    pos = InStr(header$, Chr$(10) + "From:")
  257.    If pos = 0 Then
  258.       author$ = "<Anonymous>"
  259.    Else
  260.       author$ = Mid$(header$, pos + 7)
  261.       author$ = Left$(author$, InStr(author$, new_line) - 1)
  262.    End If
  263.    pos = InStr(header$, Chr$(10) + "Message-Id:")
  264.    If pos <> 0 Then
  265.       msg_id$ = Mid$(header$, pos + 13)
  266.       msg_id$ = Left$(msg_id$, InStr(msg_id$, new_line) - 1)
  267.    Else
  268.       msg_id$ = ""
  269.    End If
  270.    edit.message_text.Text = author$ + " wrote the following: " + new_line + msg_text$
  271.    pos = InStr(author$, "<")
  272.    If pos <> 0 And InStr(author$, ">") > pos Then
  273.       author$ = Mid$(author$, pos + 1, InStr(author$, ">") - pos - 1)
  274.    Else
  275.       pos = InStr(author$, " ")
  276.       If pos <> 0 Then
  277.          author$ = Left$(author$, pos - 1)
  278.       End If
  279.    End If
  280.    edit.save_btn.enabled = true: edit.save_btn.backcolor = white
  281.    replying = True
  282.    edit.caption = list1.list(list1.listindex)
  283.    edit.Show 0
  284. End Sub
  285. Sub List1_KeyDown (keycode As Integer, Shift As Integer)
  286.    If keycode = &H22 Then   ' PgDn
  287.       list1.topindex = list1.topindex + 38
  288.    End If
  289.    If keycode = &H21 Then   ' PgUp
  290.       list1.topindex = list1.topindex - 38
  291.    End If
  292. End Sub
  293. Sub read_mail ()
  294.    mail_msg$ = get_mail(0)
  295.    While Len(mail_msg$) <> 0
  296.       Call split_header(mail_msg$, header$)
  297.       pos = InStr(header$, "Subject:")
  298.       If pos <> 0 Then
  299.          subj$ = Mid$(header$, pos + 8, InStr(pos, header$, Chr$(10)) - pos - 9)
  300.          While Left$(subj$, 1) = " "
  301.             subj$ = Mid$(subj$, 2)
  302.          Wend
  303.          list1.AddItem subj$
  304.       Else
  305.          list1.AddItem "<None>"
  306.       End If
  307.       mail_msg$ = get_mail(list1.listcount)
  308.    Wend
  309.    list1.listindex = 0
  310. End Sub
  311. Sub split_header (msg_text$, header$)
  312.    header$ = Left$(msg_text$, InStr(msg_text$, new_line + new_line) + 1)
  313.    msg_text$ = Mid$(msg_text$, InStr(msg_text$, new_line + new_line) + 4)
  314. End Sub
  315.